#include "dll.h"
#include <QDebug>
#include <QCoreApplication>

DLL::DLL()
{
    mylib.setFileName("TSCLIB.dll");    // 加载动态库
    if (!mylib.load())
    {
        qDebug() <<"======================== DLL::DLL() load_failed";
        qDebug() <<mylib.errorString();
    }
}

void DLL::ABOUT(){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(); //定义函数指针
    fun pointer = (fun)mylib.resolve("about");
    if (pointer)
    {
        pointer();
    }
    else
    {}
}
void DLL::OPENPORT(char* str){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef int ( *fun)(char*); //定义函数指针
    fun pointer = (fun)mylib.resolve("openport");
    if (pointer)
    {
        //出错点就是下方这行代码
        int p = pointer(str);
        qDebug()<<"the open return:"<<p<<endl;
    }
    else
    {}
}
void DLL::CLOSEPORT(){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(); //定义函数指针
    fun pointer = (fun)mylib.resolve("closeport");
    if (pointer)
    {
        pointer();
    }
    else
    {}
}
void DLL::CLEARBUFFER(){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(); //定义函数指针
    fun pointer = (fun)mylib.resolve("clearbuffer");
    if (pointer)
    {
        pointer();
    }
    else
    {}
}
void DLL::SENDCOMMAND(char* str){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(char* str); //定义函数指针
    fun pointer = (fun)mylib.resolve("sendcommand");
    if (pointer)
    {
        pointer(str);
    }
    else
    {}
}
void DLL::PRINTLABEL(char* str1,char* str2){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(char* str1,char* str2); //定义函数指针
    fun pointer = (fun)mylib.resolve("printlabel");
    if (pointer)
    {
        pointer(str1,str2);
    }
    else
    {}
}
void DLL::SETUP(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7); //定义函数指针
    fun pointer = (fun)mylib.resolve("setup");
    if (pointer)
    {
        pointer(str1,str2,str3,str4,str5,str6,str7);
    }
    else
    {}
}
void DLL::BARCODE(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7,char* str8,char* str9){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
    typedef void ( *fun)(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7,char* str8,char* str9); //定义函数指针
    fun pointer = (fun)mylib.resolve("barcode");
    if (pointer)
    {
        pointer(str1,str2,str3,str4,str5,str6,str7,str8,str9);
    }
    else
    {}
}
void DLL::PRINTERFONT(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
     typedef void ( *fun)(char* str1,char* str2,char* str3,char* str4,char* str5,char* str6,char* str7); //定义函数指针
     fun pointer = (fun)mylib.resolve("printerfont");
     if (pointer)
     {
         pointer(str1,str2,str3,str4,str5,str6,str7);
     }
     else
     {}
}
void DLL::WINDOWSFONT(int num1,int num2,int num3,int num4,int num5,int num6,char* str1,char* str2){
    if(!mylib.isLoaded())
    {
        qDebug() <<"load_failed";
        return;
    }
     typedef void ( *fun)(int num1,int num2,int num3,int num4,int num5,int num6,char* str1,char* str2); //定义函数指针
     fun pointer = (fun)mylib.resolve("windowsfont");
     if (pointer)
     {
         pointer(num1,num2,num3,num4,num5,num6,str1,str2);
     }
     else
     {}
}


